$(function () {
    require([],function () {
        var $user = $(".user");
        var $pwd = $(".pwd");
        var $again  = $(".again");
        var $tel = $(".tel");
        $(".btn").on("click",function () {
            var user = $user.val().trim();
            var pwd = $pwd.val().trim();
            var again = $again.val().trim();
            var tel = $tel.val().trim();
            var myreg = /^[1]{1}[345789]{1}[0-9]{9}$/;
            if(!myreg.test(tel)){
                window.wxc.xcConfirm("请输入正确的手机号", window.wxc.xcConfirm.typeEnum.error); 
            }else  if(!user){
                window.wxc.xcConfirm("用户名不能为空", window.wxc.xcConfirm.typeEnum.error);
            }else if(pwd.length < 6){
                window.wxc.xcConfirm("密码长度不能小于6", window.wxc.xcConfirm.typeEnum.error);
            }else if(pwd != again){
                window.wxc.xcConfirm("两次面不一致", window.wxc.xcConfirm.typeEnum.error);
            }else{
                $.ajax({
                    url:"/api/web/user/register",
                    type:"post",
                    data:{
                        tel:tel,
                        name:user,
                        password:pwd
                    },
                    success:function (res) {
                        console.log(res);
                        toLogin()
                    }
                });
            }
        });
        
        $("#tosign").click(function () {
            toLogin()
        });


        function toLogin() {
            var obj = getParams(window.location.href);
            var url = '/login';
            if(obj.url){
                url = url + "?url=" + obj.url;
            }
            window.location.href = url;
        }

    })
});